home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
The World of Computer Software.iso
/
vgballse.zip
/
VGBALLSE.PRG
< prev
Wrap
Text File
|
1993-01-27
|
6KB
|
237 lines
-AUTHORS
Greg Donohoe
-AUTHORS_END
-SHORT_PROG_DESCRIPTION
Creates a image of a ball with the origin at the center
-SHORT_PROG_DESCRIPTION_END
-SHORT_LIB_DESCRIPTION
Creates a image of a ball with the origin at the center
-SHORT_LIB_DESCRIPTION_END
-MAN1_LONG_DESCRIPTION
.I vgballse
creates an image of a ball. The background intensity is set by the
-b argument.
The ball can be placed anywhere, and is NOT required to lie
completely within the image boundaries. The origin of the structuring
elment is placed at the center of the sphere.
.LP
The position of the center of the circle and its diameter can all be
specified as floating point numbers, allowing sub-pixel positioning of
the circle.
.LP
The trigger input can be used to cause
.I vgballse
to re-execute when used inside cantata. No image is read from this input.
-MAN1_LONG_DESCRIPTION_END
-MAN1_EXAMPLES
vgballse -r 32 -c 32 -b 3.5 -f 100 -x 32 -y 16 -d 32 -t int
.LP
Creates a 32x32 image of type INT, with the background level at 3.5 and
the foreground at 107.5. The circle lies in this case halfway off the image
to the right. The diameter of the circle is 32 pixels.
-MAN1_EXAMPLES_END
-MAN1_RESTRICTIONS
.I vgballse
will generate only BYTE or FLOAT images.
-MAN1_RESTRICTIONS_END
-MAN1_SEE_ALSO
-MAN1_SEE_ALSO_END
-MAN3_LONG_DESCRIPTION
.I lvgballse
creates an image of a ball. The background intensity is set by the
-b argument. The foreground or circle intensity is set by the -f argument.
The circle can be placed anywhere, and is NOT required to lie
completely within the image boundaries. The origin of the structuring
elment is placed at the center of the sphere.
.LP
The position of the center of the circle and its diameter can all be
specified as floating point numbers, allowing sub-pixel positioning of
the circle.
-MAN3_LONG_DESCRIPTION_END
-MAN3_RESTRICTIONS
.I lvgballse
will generate only INT or BYTE images.
-MAN3_RESTRICTIONS_END
-MAN3_SEE_ALSO
-MAN3_SEE_ALSO_END
-USAGE_ADDITIONS
-USAGE_ADDITIONS_END
-INCLUDE_INCLUDES
-INCLUDE_INCLUDES_END
-INCLUDE_ADDITIONS
-INCLUDE_ADDITIONS_END
-INCLUDE_MACROS
-INCLUDE_MACROS_END
-MAIN_VARIABLE_LIST
struct xvimage *image;
int type;
-MAIN_VARIABLE_LIST_END
-MAIN_BEFORE_LIB_CALL
if(check_args())exit(1);
if(!vget_type(&type, vgballse->t_toggle)){
fprintf(stderr,"vgballse: Invalid data type specified\n");
exit(1);
}
if(type!=VFF_TYP_1_BYTE && type!=VFF_TYP_4_BYTE){
fprintf(stderr,"%s: Illegal image data type specified.\n",program);
exit(1);
}
-MAIN_BEFORE_LIB_CALL_END
-MAIN_LIBRARY_CALL
if(! lvgballse( &image, type, vgballse->b_float, vgballse->x_float,vgballse->y_float, vgballse->origin_logic, vgballse->d_float))
{
(void) fprintf(stderr, "lvgballse Failed\n");
exit(1);
}
-MAIN_LIBRARY_CALL_END
-MAIN_AFTER_LIB_CALL
writeimage(vgballse->o_file,image);
-MAIN_AFTER_LIB_CALL_END
-LIBRARY_INCLUDES
-LIBRARY_INCLUDES_END
-LIBRARY_INPUT
.IP "image" 15
input image structure
.IP "type" 15
the data storage type of the resulting image
.IP "bgnd" 15
the background intensity
.IP "x" 15
the X coordinate of the origin
.IP "y" 15
the Y coordinate of the origin
.IP "origin"
automatic or user-selected origin
.IP "d" 15
diameter of circle (in pixels)
-LIBRARY_INPUT_END
-LIBRARY_OUTPUT
.IP "image" 15
holds the resulting output image.
-LIBRARY_OUTPUT_END
-LIBRARY_DEF
int
lvgballse (image, type, bgnd, x, y, origin, d)
struct xvimage **image;
int type;
float bgnd,x,y,d;
int origin;
-LIBRARY_DEF_END
-LIBRARY_CODE
{
int i,j;
unsigned char *cpixel;
int *ipixel;
float r;
struct xvimage *img, *createimage();
int xorg, yorg;
int rows, cols;
rows = d;
cols = d;
img = createimage((unsigned long) rows, /* number of rows */
(unsigned long) cols, /* number of columns */
(unsigned long) type, /* data storage type */
(unsigned long) 1, /* num_of_images */
(unsigned long) 1, /* num_data_bands */
"created by vgballse", /* comment */
(unsigned long) 0, /* map_row_size */
(unsigned long) 0, /* map_col_size */
(unsigned long)
VFF_MS_NONE, /* map_scheme */
(unsigned long)
VFF_MAPTYP_NONE, /* map_storage_type */
(unsigned long)
VFF_LOC_IMPLICIT, /* location_type */
(unsigned long) 0); /* location_dim */
if (img == NULL)
{
fprintf(stderr,"lvgballse: Unable to allocate new image!\n");
*image = NULL;
return(0);
}
*image = img;
r = d/2.0;
r = r*r;
/* Set the SE origin: either center it, or accept user */
/* values */
if (!origin) {
xorg = (int)d/2.0;
yorg = (int)d/2.0;
}
else {
xorg = x;
yorg = y;
}
img->ispare1 = -xorg;
img->ispare2 = -yorg;
x = (int)d/2.0;
y = (int)d/2.0;
switch(type)
{
case VFF_TYP_1_BYTE:
cpixel = (unsigned char *)(img->imagedata);
for (i=0; i<rows; i++)
for (j=0; j<cols; j++)
if (((i-y)*(i-y)+(j-x)*(j-x)) <= r)
*cpixel++ =
(unsigned char)(sqrt(r - (i-y)*(i-y) - (j-x)*(j-x) + .5));
else *cpixel++ = bgnd;
break;
case VFF_TYP_4_BYTE:
ipixel = (int *)(img->imagedata);
for (i=0; i<rows; i++)
for (j=0; j<cols; j++)
if ((i-y)*(i-y)+(j-x)*(j-x) <= r)
*ipixel++ = (int)(sqrt(r - (i-y)*(i-y) - (j-x)*(j-x) + .5));
else *ipixel++ = bgnd;
break;
default:
fprintf(stderr,"lvgballse: Unsupported data storage type requested\n");
fprintf(stderr," Supported types: INT and BYTE\n");
return(0);
}
return(1);
}
-LIBRARY_CODE_END
-LIBRARY_MODS
-LIBRARY_MODS_END